home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / unix4pc.arc / UNIX4PC.NET
Encoding:
Text File  |  1985-09-04  |  48.7 KB  |  2,129 lines

  1.  
  2. Here are some unix style tools that also run on IBM PC.
  3. Cut it and pass it through sh.
  4. Read readme.ut1 first.
  5. Here is a list of the programs in this posting:
  6. expand, dost2b, dosb2t, hxd, which, crc16, sarch.
  7.  
  8. ----------------------- CUT HERE ----------------------
  9. # The rest of this file is a shell script which will extract:
  10. # readme.ut1 mkp makefile pcust1.bat mbstd.h msc3.h crc16.c dosb2t.c dost2b.c expand.c fcrc16.c hxd.c sarch.c which.c
  11. echo x - readme.ut1
  12. cat >readme.ut1 <<'!Funky!Stuff!'
  13. Here are a few simple tools that run identically or very similarly
  14. under msdos and unix. 
  15.  
  16. I am calling them ust1, Unix Style Tools. Couldn't come up with 
  17. a better name.
  18.  
  19. They have only minimally been tested under msdos and bsd4.2.
  20. MSC 3.0 was used under msdos.
  21. I did make an effort to make the code portable. They probably would 
  22. run under a few other systems.
  23.  
  24. Mail bug reports and problems to me. I'll re-post.
  25.  
  26. expand:
  27.  *  Expand mimics Unix's expand. It is not a full implementation.
  28.  *  Does not support [-tab1,tab2,..,tabn].
  29.  *  Expand is a filter.
  30.  *  It processes the named files or the standard input.
  31.  *  It writes to standard output with tabs changed into blanks.
  32.  *  
  33.  * Usages:
  34.  *  expand [-tabstop] [i_files]
  35.     Back space can easily be added to it.
  36.  
  37. dost2b:
  38.  *  dost2b is a filter.
  39.  *  dost2b processes i_files or the standard input.
  40.  *  dost2b writes to o_file or standard output.
  41.  *  Converts a DOS text file to binary file.
  42.  *  Replaces <cr><lf> to <lf>.
  43.  *
  44.  * Usages:
  45.  *  dost2b [-o] <o_file> <i_files>
  46.  
  47. dosb2t:
  48.  *  dosb2t is a filter.
  49.  *  dosb2t processes i_files or the standard input.
  50.  *  dosb2t writes to o_file or standard output.
  51.  *  Converts a DOS binary file to text file.
  52.  *  Replaces <lf> with <cr><lf>.
  53.  *  
  54.  * Usages:
  55.  *  dosb2t [-o] <o_file> <i_files>
  56.  
  57. hxd:
  58.  *  hxd, Hexadecimal dump is similar unix's "od -x"
  59.  *  Displays the contents of a file in hexadecimal.
  60.  *  If a byte is printable, it is also printed.
  61.  *  For each in put file name of the file is first emited.
  62.  *      file: <i_file>
  63.  *  last line for each input file is length of the file in 
  64.  *      "dec_add:hex_add" format.
  65.  *
  66.  * Usages:
  67.  *  hxd [-o] <o_file> <i_files>
  68.     See Comments in hxd.c.
  69.  
  70. which:
  71.  *  Tries to mimic Unix's which as closely as possible.
  72.  *  
  73.  * Usages:
  74.  *  which <i_files>
  75.     This is basically Larry Barello's which. 
  76.     For DOS .{com,exe,bat} are tested for existance.
  77.     Only the first one that exists is printed.
  78.     Internal DOS programs could later be added.
  79.  
  80. crc16:
  81.     This is basically Hugh Redelmeir's version.
  82.     I needed to modify it so that it could also be
  83.     used by sarch.
  84.  
  85. sarch:
  86.  *      This is a simple archive utility program.
  87.  *      Sarch tries to only rely on the C stdio library functions.
  88.  *      When transferring multiple files between two machines that only have a
  89.  *      single file transfer utility, sarch becomes handy. Multiple files
  90.  *      are converted to a sinle file on one end, transfered to the other 
  91.  *      machine and extracted to the original files at the destination.
  92.  *      System dependent features are very few, keeping it simple
  93.  *      and portable. Efficiency is sacrificed for portability.
  94.  *      CRCs are computed when updateing and when extracting.
  95.  *  
  96.  * Usage:
  97.  *  sarch -{m,u,x,a,t} archname file1 .. filen
  98.  *      -m      Print file names within the archive.
  99.  *      -u      Add or update files to the archive.
  100.  *      -x      Extract files from archive.
  101.  *      -a      Extract all files from the rachive.
  102.  *      -t      PCDOS related. When extracting, test mode is set.
  103.     Sarch is NOT COMPLETE. 
  104.     I am posting it because it can be useful if used carefully.
  105.     No flames on this one, please.
  106.     I am also not happy with th command syntax.
  107.     Only -u and -a work. As is, it is only useful for moving files
  108.     around. 
  109.     sarch -u ar file1 filen   , on one end.
  110.     sarch -a ar , on the other end.
  111.  
  112.  
  113. FILES:
  114.     mkp:
  115.         Is a Csh script that runs make.
  116.         It can be useful when you are supporting native and cross
  117.         development. Some don't like it. I do.
  118.     makefile:
  119.         File dependencies only. Needs mkp.
  120.     pcust1.bat:
  121.         run this on the pc to create everything.
  122.     mbstd.h:
  123.         Standard Header I use.
  124.     expand.c dost2b.c dosb2t.c hxd.c sarch.c which.c fcrc16.c crc16.c:
  125.         C source files.
  126.     readme.ut1:
  127.         This file.
  128.     
  129. TO RUN:
  130.     bsd4.2
  131.         first make mkp executable.
  132.         mkp 
  133.     msdos, msc
  134.         make sure that all headers and libraries are there.
  135.         make sure ssetargv.obj is in current directory.
  136.         run pcust1.bat
  137. !Funky!Stuff!
  138. echo x - mkp
  139. cat >mkp <<'!Funky!Stuff!'
  140. #!/bin/csh -f
  141. # This is the make pre-processor program written in the 'C' shell.
  142. #
  143. #   mkp defines a group of parameters and passes them to make.
  144. #   SWITCHES:
  145. #       -f <filename>
  146. #           source <filename. priore to invoking make.
  147. #           If -f is not present and .mkprc exists in the current directory
  148. #           it is sourced. Otherwise if .mkprc exists in the home directory
  149. #           it is sourced.
  150. #       -- 
  151. #           argument parsing is terminated remainder of command line is passed
  152. #           to make as is.
  153. #
  154. set MKPFILE=.mkprc
  155. set mkpname=$0
  156. set mkpname=$mkpname:t
  157. # ### VISIBLE MAKE TOOLS
  158. set MAKE=make
  159. set CC=cc
  160. set AS="as -"
  161. set LK=""
  162. set LD=""
  163. set LINT="lint -u"
  164. set REMOVE="rm -f"
  165. set CTAGS="ctags -w"
  166. # Internal parametrs
  167. set INCFLAGS = -I.
  168. # ### VISIBLE MAKE PARAMETERS
  169. #set CFLAGS = "${INCFLAGS} -DBSD4_2 -Uunix -DMSDOS"
  170. set CFLAGS = "${INCFLAGS} -DBSD4_2 "
  171. set LINTFLAGS = ${INCFLAGS}
  172. set TARGETS
  173. # MKP FLAGS
  174. set S_MKPFILE
  175. umask 002
  176. #^L
  177. #
  178. # Gather command line options
  179. #
  180. foreach i ($*)
  181.     switch ($1)
  182.     case -f:
  183.         shift argv
  184.         set S_MKPFILE=$1
  185.         breaksw
  186.     case --:
  187.         shift argv
  188.         break
  189.     default:
  190.         break
  191.         breaksw
  192.     endsw
  193.     shift argv
  194. end
  195. #
  196. #
  197. #
  198. #
  199. if ("$S_MKPFILE" != "") then
  200.     set MKPFILE = "$S_MKPFILE"
  201.     source $MKPFILE
  202. else if (-f $MKPFILE) then
  203.     source $MKPFILE
  204. else if (-f $HOME/$MKPFILE) then
  205.     source $HOME/$MKPFILE
  206. endif
  207. #
  208. set TARGETS="$*"
  209. #
  210. $MAKE  "CC=$CC" "AS=$AS" \
  211.     "CFLAGS=$CFLAGS" "LINTFLAGS=$LINTFLAGS" \
  212.     "LINT=$LINT"  \
  213.     "REMOVE=$REMOVE" "CTAGS=$CTAGS" \
  214.     $TARGETS
  215. set ret=$status
  216. if ("$ret" != "0") then
  217.     exit 1
  218. endif
  219. exit 0
  220. !Funky!Stuff!
  221. echo x - makefile
  222. cat >makefile <<'!Funky!Stuff!'
  223. # ::::::::::::::::::::::::::::::::::::::::::::::::::
  224. #
  225. #  File: Makefile
  226. #  Description: Makefile for creating  UST1
  227. #
  228. #
  229. #  Audit Trail:  $Log:  makefile,v $
  230. # Revision 1.1  85/08/28  08:38:38  mohsen
  231. # original posting to the net
  232. #
  233. #  $Header: makefile,v 1.1 85/08/28 08:38:38 mohsen Exp $
  234. #
  235. # ::::::::::::::::::::::::::::::::::::::::::::::::::
  236.  
  237. MAKEFILE = makefile
  238. TARGET = ust1
  239. PUB_H = mbstd.h msc3.h
  240. LCL_H =
  241. LCL_C = expand.c dost2b.c dosb2t.c hxd.c sarch.c which.c fcrc16.c \
  242.                 crc16.c 
  243. C_SRC =  ${PUB_H} ${LCL_H} ${LCL_C}
  244.  
  245. ${TARGET}: expand dost2b dosb2t hxd crc16 which sarch
  246. #
  247. expand:   expand.o
  248.                 cc -o expand expand.o
  249. #
  250. dost2b:  dost2b.o
  251.                 cc -o dost2b dost2b.o
  252. #
  253. dosb2t:  dosb2t.o
  254.                 cc -o dosb2t dosb2t.o
  255. #
  256. hxd:     hxd.o
  257.                 cc -o hxd hxd.o
  258. #
  259. crc16:   crc16.o fcrc16.o
  260.                 cc -o crc16 crc16.o fcrc16.o
  261. #
  262. sarch:   sarch.o
  263.                 cc -o sarch sarch.o fcrc16.o
  264. #
  265. which:   which.o
  266.                 cc -o which which.o
  267. #
  268. e_make:
  269.         @echo ${MAKEFILE}
  270. e_pub_h:
  271.         @echo ${PUB_H}
  272. e_lcl_h:
  273.         @echo ${LCL_H}
  274. e_lcl_c:
  275.         @echo ${LCL_C}
  276. e_c_src:
  277.         @echo ${C_SRC}
  278. #
  279. ctags:  ${LCL_C}
  280.                 $(CTAGS) $(LCL_C)
  281. #
  282. lint:
  283.                 $(LINT) $(LCL_C)
  284.  
  285. !Funky!Stuff!
  286. echo x - pcust1.bat
  287. cat >pcust1.bat <<'!Funky!Stuff!'
  288. cl -c -DMSDOS expand.c
  289. cl -o expand expand.obj ssetargv.obj
  290. cl -c -DMSDOS dost2b.c
  291. cl -o dost2b dost2b.obj ssetargv.obj
  292. cl -c -DMSDOS dosb2t.c
  293. cl -o dosb2t dosb2t.obj ssetargv.obj
  294. cl -c -DMSDOS hxd.c
  295. cl -o hxd hxd.obj ssetargv.obj
  296. cl -c -DMSDOS fcrc16.c
  297. cl -c -DMSDOS crc16.c
  298. cl -o crc16 crc16.obj fcrc16.obj ssetargv.obj
  299. cl -c -DMSDOS sarch.c
  300. cl -o sarch sarch.obj fcrc16.obj ssetargv.obj
  301. cl -c -DMSDOS which.c
  302. cl -o which which.obj ssetargv.obj
  303. !Funky!Stuff!
  304. echo x - mbstd.h
  305. cat >mbstd.h <<'!Funky!Stuff!'
  306. #ifndef MBSTD_H
  307. #define MBSTD_H
  308.  
  309. #define CHAR    char
  310. #define SCHAR   char
  311. typedef unsigned char  UCHAR;
  312.  
  313. #define INT     int
  314. #define SINT    int
  315. typedef unsigned int UINT;
  316.  
  317. #define SHORT   short
  318. #define SSHORT  short
  319. typedef unsigned short USHORT;
  320.  
  321. #define LONG    long
  322. #define SLONG   long
  323. typedef unsigned long ULONG;
  324.  
  325. #define DOUBLE  double
  326.  
  327. #define BOOL    int
  328. #define SUCC_FAIL   int 
  329. #ifndef VOID
  330. #define VOID    void
  331. #endif
  332.  
  333. #define STATIC  static      /* Names not needed outside this src module  */
  334.  
  335. #define LOCAL               /* Names not needed outside this software module */
  336. #define LCL_XTRN extern     /* Names defined within this software module */
  337.  
  338. #define PUBLIC              /* Names needed outside this software module */
  339. #define EXTERN  extern      /* Names defined outside this software module */
  340.  
  341. #define TRUE    1
  342. #define FALSE   0
  343.  
  344. #define SUCCESS 0
  345. #define FAIL    (-1)
  346.  
  347. #endif MBSTD_H
  348. !Funky!Stuff!
  349. echo x - msc3.h
  350. cat >msc3.h <<'!Funky!Stuff!'
  351. #ifndef MSC3_H
  352. #define MSC3_H
  353.  
  354. #ifdef unix
  355. #define O_TEXT   0x4000
  356. #define O_BINARY 0x8000
  357. setmode(handle, mode)
  358. int handle;
  359. int mode;
  360. {}
  361. #endif
  362.  
  363. #endif MSC3_H
  364. !Funky!Stuff!
  365. echo x - crc16.c
  366. cat >crc16.c <<'!Funky!Stuff!'
  367. /*+
  368.  * File: crc16.c
  369.  * Description:
  370.  *  Computes crc for the named filenames.
  371.  *  Output has this formatt.
  372.  *      file=[i_file], size=[fsize], crc=[decval](dec)=[hexval](hex)
  373.  *  
  374.  * Usages:
  375.  *  crc16 <i_files>
  376.  *
  377.  *  Author: Mohsen Banan.
  378.  *
  379.  *  This program is public domain software, no warranty intended or
  380.  *  implied.
  381.  *  General permission to copy or modify, but not for profit,  is
  382.  *  hereby  granted.
  383.  *
  384.  * Functions:
  385.  *
  386.  *
  387.  * Audit Trail:  $Log:  crc16.c,v $
  388.  * Revision 1.1  85/08/28  08:38:12  mohsen
  389.  * original posting to the net
  390.  * 
  391.  * 
  392.  *
  393. -*/
  394.  
  395. #ifdef RCS_VER
  396. static char *rcs = "$Header: crc16.c,v 1.1 85/08/28 08:38:12 mohsen Exp $";
  397. #endif
  398.  
  399. /* #includes */
  400. #include "mbstd.h"
  401. #include <stdio.h>
  402. #include <ctype.h>
  403. #include <fcntl.h>
  404. #ifdef unix
  405. #include "msc3.h"
  406. #endif
  407.  
  408. /* #defines */
  409.  
  410. /* external variables */
  411.  
  412. /* referenced external function declarations */
  413. EXTERN USHORT fcrc16();
  414. /* internal function declarations */
  415. PUBLIC VOID crc16();
  416. PUBLIC VOID cant_open();
  417. STATIC VOID usage();
  418.  
  419. /* global variables */
  420.  
  421. /* static variables */
  422. STATIC CHAR * prog_name;
  423.  
  424.  
  425. INT
  426. main (argc, argv)
  427. INT argc;
  428. CHAR * argv[];
  429. {
  430.     crc16(argc, argv);
  431. }
  432.     
  433. ^L
  434. --MORE--(22%)/*<
  435.  * Function:crc16
  436.  * Description:
  437.  *
  438.  * Returns:
  439.  *  VOID
  440.  *  
  441. >*/
  442. PUBLIC VOID 
  443. crc16 (argc,argv)
  444. INT argc;
  445. CHAR * argv[];
  446. {
  447.     FILE * i_fp;
  448.     FILE * o_fp;
  449.  
  450.     INT i;
  451.     USHORT crc;
  452.     LONG fsize ;
  453.  
  454.     i_fp = stdin;
  455.     o_fp = stdout;
  456.     prog_name = argv[0];
  457.     for (i=1; i<argc; ++i) {
  458.         if (*argv[i] == '-') {
  459.             /* To handle concatenated switches */
  460.             INT j;
  461.             j=i;
  462.             while (*(++argv[j])) {
  463.                 switch (*argv[j]) {
  464.                 case 'o':
  465.                 case 'O':
  466.                     if ( !(o_fp = fopen(argv[++i], "w")) ) {
  467.                         cant_open (prog_name, argv[i]);
  468.                         exit (1);
  469.                     }
  470.                     break;
  471.                 default:
  472.                     usage();
  473.                     exit(1);
  474.                 } /* switch (*argv[j]) */
  475.             } /* while (*(++argv[j])) */
  476.         } /* if '-' */
  477.         else {
  478.             if (!(i_fp = fopen (argv[i], "r"))) {
  479.                 cant_open (prog_name, argv[i]);
  480.                 exit (1);
  481.             } 
  482.             setmode (fileno(i_fp), O_BINARY);
  483.             setmode (fileno(o_fp), O_TEXT);
  484.             crc = fcrc16 (i_fp, 0, &fsize);
  485.             fprintf (o_fp, "file=%s, size=%ld, crc=%u(dec)=%x(hex)\n",
  486.                     argv[i], fsize, crc, crc);
  487.             fclose (i_fp);
  488.         }
  489.     } /* for i<argc */
  490.     fclose (o_fp);
  491.     exit (0);
  492. }
  493.  
  494. PUBLIC VOID
  495. cant_open (prog_name,filename)
  496. CHAR * prog_name;
  497. CHAR * filename;
  498. {
  499.     fprintf (stderr, "%s :can not open %s \n", prog_name, filename);
  500.  
  501. STATIC VOID
  502. usage ()
  503. {
  504.     fprintf (stderr, "Usage: %s <i_files> \n", prog_name);
  505. }
  506.  
  507.  
  508.  
  509. !Funky!Stuff!
  510. echo x - dosb2t.c
  511. cat >dosb2t.c <<'!Funky!Stuff!'
  512.  
  513. /*+
  514.  * File: dosb2t.c
  515.  * Description:
  516.  *  dosb2t is a filter.
  517.  *  dosb2t processes i_files or the standard input.
  518.  *  dosb2t writes to o_file or standard output.
  519.  *
  520.  *  Converts a DOS binary file to text file.
  521.  *  Replaces <lf> with <cr><lf>.
  522.  *  
  523.  * Usages:
  524.  *  dosb2t [-o] <o_file> <i_files>
  525.  *
  526.  *
  527.  *  Author: Mohsen Banan.
  528.  *
  529.  *  This program is public domain software, no warranty intended or
  530.  *  implied.
  531.  *  General permission to copy or modify, but not for profit,  is
  532.  *  hereby  granted.
  533.  *
  534.  *
  535.  * Functions:
  536.  *
  537.  *
  538.  * Audit Trail:  $Log:  dosb2t.c,v $
  539.  * Revision 1.1  85/08/28  08:38:24  mohsen
  540.  * original posting to the net
  541.  * 
  542.  * 
  543.  *
  544. -*/
  545.  
  546. #ifdef RCS_VER
  547. static char *rcs = "$Header: dosb2t.c,v 1.1 85/08/28 08:38:24 mohsen Exp $";
  548. #endif
  549.  
  550. /* #includes */
  551. #include "mbstd.h"
  552. #include <stdio.h>
  553. #include <ctype.h>
  554. #include <fcntl.h>
  555. #ifdef unix
  556. #include "msc3.h"
  557. #endif
  558.  
  559. /* #defines */
  560.  
  561. /* external variables */
  562.  
  563. /* referenced external function declarations */
  564.  
  565. /* internal function declarations */
  566. PUBLIC VOID dosb2t();
  567. PUBLIC VOID cant_open();
  568. STATIC VOID usage();
  569.  
  570. /* global variables */
  571.  
  572. /* static variables */
  573. STATIC CHAR * prog_name;
  574.  
  575.  
  576. INT
  577. main (argc, argv)
  578. INT argc;
  579. CHAR * argv[];
  580. {
  581.     dosb2t(argc, argv);
  582. }
  583.     
  584. ^L
  585. --MORE--(29%)/*<
  586.  * Function:dosb2t
  587.  * Description:
  588.  *
  589.  * Returns:
  590.  *  VOID
  591.  *  
  592. >*/
  593. PUBLIC VOID 
  594. dosb2t (argc,argv)
  595. INT argc;
  596. CHAR * argv[];
  597. {
  598.     FILE * i_fp;
  599.     FILE * o_fp;
  600.  
  601.     INT i;
  602.     INT c;
  603.  
  604.     i_fp = stdin;
  605.     o_fp = stdout;
  606.     prog_name = argv[0];
  607.     for (i=1; i<argc; ++i) {
  608.         if (*argv[i] == '-') {
  609.             /* To handle concatenated switches */
  610.             INT j;
  611.             j=i;
  612.             while (*(++argv[j])) {
  613.                 switch (*argv[j]) {
  614.                 case 'o':
  615.                 case 'O':
  616.                     if ( !(o_fp = fopen(argv[++i], "w")) ) {
  617.                         cant_open (prog_name, argv[i]);
  618.                         exit (1);
  619.                     }
  620.                     break;
  621.                 default:
  622.                     usage();
  623.                     exit(1);
  624.                 } /* switch (*argv[j]) */
  625.             } /* while (*(++argv[j])) */
  626.         } /* if '-' */
  627.         else {
  628.             if (!(i_fp = fopen (argv[i], "r"))) {
  629.                 cant_open (prog_name, argv[i]);
  630.                 exit (1);
  631.             } 
  632.             setmode (fileno(i_fp), O_BINARY);
  633.             setmode (fileno(o_fp), O_TEXT);
  634.             while (( c = getc (i_fp)) != EOF) {
  635.                 putc (c, o_fp);
  636.             }
  637.             fclose (i_fp);
  638.         }
  639.     } /* for i<argc */
  640.     fclose (o_fp);
  641.     exit (0);
  642. }
  643.  
  644. PUBLIC VOID
  645. cant_open (prog_name,filename)
  646. CHAR * prog_name;
  647. CHAR * filename;
  648. {
  649.     fprintf (stderr, "%s :can not open %s \n", prog_name, filename);
  650.  
  651. STATIC VOID
  652. usage ()
  653. {
  654.     fprintf (stderr, "Usage: %s [-o] <o_file> <i_files> \n", prog_name);
  655. }
  656.  
  657.  
  658. !Funky!Stuff!
  659. echo x - dost2b.c
  660. cat >dost2b.c <<'!Funky!Stuff!'
  661. /*+
  662.  * File: dost2b.c
  663.  * Description:
  664.  *  dost2b is a filter.
  665.  *  dost2b processes i_files or the standard input.
  666.  *  dost2b writes to o_file or standard output.
  667.  *
  668.  *  Converts a DOS text file to binary file.
  669.  *  Replaces <cr><lf> to <lf>.
  670.  *
  671.  * Usages:
  672.  *  dost2b [-o] <o_file> <i_files>
  673.  * 
  674.  *
  675.  *  Author: Mohsen Banan.
  676.  *
  677.  *  This program is public domain software, no warranty intended or
  678.  *  implied.
  679.  *  General permission to copy or modify, but not for profit,  is
  680.  *  hereby  granted.
  681.  *
  682.  *
  683.  * Functions:
  684.  *
  685.  *
  686.  * Audit Trail:  $Log:  dost2b.c,v $
  687.  * Revision 1.1  85/08/28  08:38:28  mohsen
  688.  * original posting to the net
  689.  * 
  690.  * 
  691.  *
  692. -*/
  693.  
  694. #ifdef RCS_VER
  695. static char *rcs = "$Header: dost2b.c,v 1.1 85/08/28 08:38:28 mohsen Exp $";
  696. #endif
  697.  
  698. /* #includes */
  699. #include "mbstd.h"
  700. #include <stdio.h>
  701. #include <ctype.h>
  702. #include <fcntl.h>
  703. #ifdef unix
  704. #include "msc3.h"
  705. #endif
  706.  
  707. /* #defines */
  708.  
  709. /* external variables */
  710.  
  711. /* referenced external function declarations */
  712.  
  713. /* internal function declarations */
  714. PUBLIC VOID dost2b();
  715. PUBLIC VOID cant_open();
  716. STATIC VOID usage();
  717.  
  718. /* global variables */
  719.  
  720. /* static variables */
  721. STATIC CHAR * prog_name;
  722.  
  723. INT
  724. main (argc, argv)
  725. INT argc;
  726. CHAR * argv[];
  727. {
  728.     dost2b(argc, argv);
  729. }
  730.     
  731. ^L
  732. --MORE--(35%)/*<
  733.  * Function:dost2b
  734.  * Description:
  735.  *
  736.  * Returns:
  737.  *  VOID
  738.  * 
  739. >*/
  740. PUBLIC VOID 
  741. dost2b (argc,argv)
  742. INT argc;
  743. CHAR * argv[];
  744. {
  745.     FILE * i_fp;
  746.     FILE * o_fp;
  747.  
  748.     INT i;
  749.     INT c;
  750.  
  751.     i_fp = stdin;
  752.     o_fp = stdout;
  753.     prog_name = argv[0];
  754.     for (i=1; i<argc; ++i) {
  755.         if (*argv[i] == '-') {
  756.             /* To handle concatenated switches */
  757.             INT j;
  758.             j=i;
  759.             while (*(++argv[j])) {
  760.                 switch (*argv[j]) {
  761.                 case 'o':
  762.                 case 'O':
  763.                     if ( !(o_fp = fopen(argv[++i], "w")) ) {
  764.                         cant_open (prog_name, argv[i]);
  765.                         exit (1);
  766.                     }
  767.                     break;
  768.                 default:
  769.                     usage();
  770.                     exit(1);
  771.                 } /* switch (*argv[j]) */
  772.             } /* while (*(++argv[j])) */
  773.         } /* if '-' */
  774.         else {
  775.             if (!(i_fp = fopen (argv[i], "r"))) {
  776.                 cant_open (prog_name, argv[i]);
  777.                 exit (1);
  778.             } 
  779.             setmode (fileno(i_fp), O_TEXT);
  780.             setmode (fileno(o_fp), O_BINARY);
  781.             while (( c = getc (i_fp)) != EOF) {
  782.                 putc (c, o_fp);
  783.             }
  784.             fclose (i_fp);
  785.         }
  786.     } /* for i<argc */
  787.     fclose (o_fp);
  788.     exit (0);
  789. }
  790.  
  791. PUBLIC VOID
  792. cant_open (prog_name,filename)
  793. CHAR * prog_name;
  794. CHAR * filename;
  795. {
  796.     fprintf (stderr, "%s :can not open %s \n", prog_name, filename);
  797.  
  798. STATIC VOID
  799. usage ()
  800. {
  801.     fprintf (stderr, "Usage: %s [-o] <o_file> <i_files> \n", prog_name);
  802. }
  803.  
  804.  
  805. !Funky!Stuff!
  806. echo x - expand.c
  807. cat >expand.c <<'!Funky!Stuff!'
  808.  
  809. /*+
  810.  * File: expand.c
  811.  * Description:
  812.  *  Expand mimics Unix's expand. It is not a full implementation.
  813.  *  Does not support [-tab1,tab2,..,tabn].
  814.  *
  815.  *  Expand is a filter.
  816.  *  It processes the named files or the standard input.
  817.  *  It writes to standard output with tabs changed into blanks.
  818.  *  
  819.  * Usages:
  820.  *  expand [-tabstop] [i_files]
  821.  *
  822.  *
  823.  *  Author: Mohsen Banan.
  824.  *
  825.  *  This program is public domain software, no warranty intended or
  826.  *  implied.
  827.  *  General permission to copy or modify, but not for profit,  is
  828.  *  hereby  granted.
  829.  *
  830.  * Functions:
  831.  *
  832.  *
  833.  * Audit Trail:  $Log:  expand.c,v $
  834.  * Revision 1.1  85/08/28  08:38:31  mohsen
  835.  * original posting to the net
  836.  * 
  837.  * Revision 1.1  85/08/14  13:44:13  mohsen
  838.  * Initial revision
  839.  * 
  840.  * 
  841.  *
  842. -*/
  843.  
  844. #ifdef RCS_VER
  845. static char *rcs = "$Header: expand.c,v 1.1 85/08/28 08:38:31 mohsen Exp $";
  846. #endif
  847.  
  848. /* #includes */
  849. #include "mbstd.h"
  850. #include <stdio.h>
  851. #include <ctype.h>
  852. #include <fcntl.h>
  853. #ifdef unix
  854. #include "msc3.h"
  855. #endif
  856.  
  857. /* #defines */
  858.  
  859. /* external variables */
  860.  
  861. /* referenced external function declarations */
  862.  
  863. /* internal function declarations */
  864. PUBLIC VOID expand();
  865. PUBLIC VOID tab_putc();
  866. PUBLIC VOID cant_open();
  867. STATIC VOID usage();
  868.  
  869. /* global variables */
  870.  
  871. /* static variables */
  872. STATIC CHAR * prog_name;
  873. STATIC INT tabstop;
  874. STATIC INT cpos;
  875.  
  876. INT
  877. main (argc, argv)
  878. INT argc;
  879. CHAR * argv[];
  880. {
  881.     expand(argc, argv);
  882. }
  883.     
  884. ^L
  885. --MORE--(41%)/*<
  886.  * Function:expand
  887.  * Description:
  888.  *  Parses the command line and calls tab_putc.
  889.  *
  890.  * Returns:
  891.  *  VOID
  892.  * 
  893. >*/
  894. PUBLIC VOID 
  895. expand (argc,argv)
  896. INT argc;
  897. CHAR * argv[];
  898. {
  899.     FILE * i_fp;
  900.     FILE * o_fp;
  901.  
  902.     INT i;
  903.     INT c;
  904.  
  905.     i_fp = stdin;
  906.     o_fp = stdout;
  907.     tabstop = 8;
  908.     prog_name = argv[0];
  909.     for (i=1; i<argc; ++i) {
  910.         if (*argv[i] == '-') {
  911.             /* To handle concatenated switches */
  912.             INT j;
  913.             j=i;
  914.             while (*(++argv[j])) {
  915.                 if (isdigit(*(argv[j]))) {
  916.                     tabstop = atoi(argv[j]);
  917.                     break;
  918.                 }
  919. #if 0
  920.                 switch (*argv[j]) {
  921.                 case 'o':
  922.                 case 'O':
  923.                     if ( !(o_fp = fopen(argv[++i], "w")) ) {
  924.                         cant_open (prog_name, argv[i]);
  925.                         exit (1);
  926.                     }
  927.                     break;
  928.                 default:
  929.                     usage();
  930.                     exit(1);
  931.                 } /* switch (*argv[j]) */
  932. #endif
  933.             } /* while (*(++argv[j])) */
  934.         } /* if '-' */
  935.         else {
  936.             if (!(i_fp = fopen (argv[i], "r"))) {
  937.                 cant_open (prog_name, argv[i]);
  938.                 exit (1);
  939.             } 
  940.             setmode (fileno(i_fp), O_TEXT);
  941.             setmode (fileno(o_fp), O_TEXT);
  942.             cpos = 0;
  943.             while (( c = getc (i_fp)) != EOF) {
  944.                 tab_putc (c, o_fp);
  945.             }
  946.             fclose (i_fp);
  947.         }
  948.     } /* for i<argc */
  949.     fclose (o_fp);
  950.     exit (0);
  951. }
  952.  
  953. ^L
  954. --MORE--(44%)/*<
  955.  * Function:tab_putc
  956.  * Description:
  957.  *  Converts tabs to the correct number of spaces (tabstop).
  958.  *  tab_putc is recursive.
  959.  *
  960.  * Returns:
  961.  *  VOID
  962.  *
  963. >*/
  964. PUBLIC VOID
  965. tab_putc (c, o_fp)
  966. INT  c;
  967. FILE * o_fp;
  968. {
  969.     if (c == '\n') {
  970.         cpos = 0;
  971.         putc (c, o_fp);
  972.     } else if ( c== '\t') {
  973.         do {
  974.             tab_putc(' ', o_fp);
  975.         } while (cpos % tabstop);
  976.     }
  977.     else {
  978.         cpos++;
  979.         putc (c, o_fp);
  980.     }
  981. }
  982.  
  983. PUBLIC VOID
  984. cant_open (prog_name,filename)
  985. CHAR * prog_name;
  986. CHAR * filename;
  987. {
  988.     fprintf (stderr, "%s :can not open %s \n", prog_name, filename);
  989.  
  990. #if 0
  991. STATIC VOID
  992. usage ()
  993. {
  994.     fprintf (stderr, "Usage: %s [-tabstop] [i_files]\n", prog_name);
  995. }
  996. #endif
  997.  
  998. !Funky!Stuff!
  999. echo x - fcrc16.c
  1000. cat >fcrc16.c <<'!Funky!Stuff!'
  1001. /*+
  1002.  * File: fcrc16
  1003.  * Description:
  1004.  *      Calculates crc, given a file pointer.
  1005.  *
  1006.  *
  1007.  *  Author: Mohsen Banan.
  1008.  *
  1009.  *  This program is public domain software, no warranty intended or
  1010.  *  implied.
  1011.  *  General permission to copy or modify, but not for profit,  is
  1012.  *  hereby  granted.
  1013.  *
  1014.  *
  1015.  * Functions:
  1016.  *
  1017.  *
  1018.  * Audit Trail:  $Log:  fcrc16.c,v $
  1019.  * Revision 1.1  85/08/28  08:38:33  mohsen
  1020.  * original posting to the net
  1021.  * 
  1022.  * 
  1023.  *
  1024. -*/
  1025.  
  1026. #ifdef RCS_VER
  1027. static char *rcs = "$Header: fcrc16.c,v 1.1 85/08/28 08:38:33 mohsen Exp $";
  1028. #endif
  1029.  
  1030. /* #includes */
  1031. #include "mbstd.h"
  1032. #include <stdio.h>
  1033.  
  1034. /* #defines */
  1035.  
  1036. /* external variables */
  1037.  
  1038. /* referenced external function declarations */
  1039.  
  1040. /* internal function declarations */
  1041.  
  1042. /* global variables */
  1043.  
  1044. /* static variables */
  1045.  
  1046. ^L
  1047. --MORE--(48%)/*<
  1048.  * Function:crc16_table
  1049.  * Description:
  1050.  *
  1051.  *  * Calculate CRC16 of a file.
  1052.  *  * CRC16 polynomial: x**0 + x**2 + x**15 + x**16 (0xA001)
  1053.  *  * (CCITT polynomial: x**0 + x**5 + x**12 + x**16 (0x8408))
  1054.  *  * 
  1055.  *  * D. Hugh Redelmeier  1983 April 15
  1056.  *
  1057.  *  Mohsen Banan: I don't know how CRCs work yet. 
  1058.  *  None of what is to follow is original work.
  1059.  *
  1060.  *
  1061.  * Returns:
  1062.  * 
  1063. >*/
  1064. #if 0
  1065. VOID 
  1066. crc16_table()
  1067. {
  1068.     register unsigned s, t;
  1069.     register int i;
  1070.  
  1071.     printf("unsigned short crctab[256] = {");
  1072.     for (t=0; ; ) {
  1073.         if (t%8 == 0)
  1074.             printf("\n");
  1075.         s = t;
  1076.         for (i=8; i--; )
  1077.             s = s>>1 ^ (s&1? 0xA001 : 0);
  1078.         printf("\t0x%04x", s);
  1079.         if (++t == 256)
  1080.             break;
  1081.         printf(",");
  1082.         }
  1083.     printf("};\n");
  1084. }
  1085. #endif
  1086.  
  1087. unsigned short crctab[256] = {
  1088.     0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
  1089.     0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
  1090.     0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
  1091.     0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
  1092.     0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
  1093.     0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
  1094.     0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
  1095.     0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
  1096.     0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
  1097.     0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
  1098.     0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
  1099.     0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
  1100.     0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
  1101.     0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
  1102.     0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
  1103.     0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
  1104.     0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
  1105.     0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
  1106.     0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
  1107.     0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
  1108.     0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
  1109.     0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
  1110.     0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
  1111.     0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
  1112.     0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
  1113.     0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
  1114.     0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
  1115.     0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
  1116.     0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
  1117.     0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
  1118.     0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
  1119.     0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040};
  1120.  
  1121.  
  1122. ^L
  1123. --MORE--(54%)/*<
  1124.  * Function:fcrc16
  1125.  * Description:
  1126.  *  The algorithm comes from 
  1127.  *  "Byte-wise CRC Calculations" by Aram Perez,
  1128.  *  IEEE Micro June 1983 pp.40-50
  1129.  *
  1130.  * Returns:
  1131.  *  VOID
  1132.  * 
  1133. >*/
  1134.     
  1135. PUBLIC USHORT 
  1136. fcrc16 (i_fp, prev_crc, p_fsize)
  1137. FILE * i_fp;
  1138. USHORT prev_crc;
  1139. LONG * p_fsize;
  1140. {
  1141.     USHORT crc, x;
  1142.     INT c;
  1143.     LONG  fsize;
  1144.  
  1145.     crc = prev_crc;
  1146.     fsize = 0L;
  1147.     while ((c=getc(i_fp)) != EOF) {
  1148.         /* these are really the same.
  1149.          * crc = crctab[(crc^c)&0xff] ^ crc>>8;
  1150.          */
  1151.         x = (c^crc) & 0xFF;
  1152.         crc >>= 8;
  1153.         crc ^= crctab[x];
  1154.         ++fsize;
  1155.     }
  1156.         rewind(i_fp);           /* I don't like side effects */
  1157.     *p_fsize = fsize;
  1158.     return (crc);
  1159. }
  1160. !Funky!Stuff!
  1161. echo x - hxd.c
  1162. cat >hxd.c <<'!Funky!Stuff!'
  1163. /*+
  1164.  * File: hxd
  1165.  * Description:
  1166.  *  hxd, Hexadecimal dump is similar unix's "od -x"
  1167.  *  Displays the contents of a file in hexadecimal.
  1168.  *  If a byte is printable, it is also printed.
  1169.  *  format of output is :
  1170.  *  dec_add:hex_add word word word word word word word word  string  
  1171.  *  where:
  1172.  *      dec_add == Start address for that line in decimal. 
  1173.  *      hex_add == Start address for that line in hex. 
  1174.  *      word == Representation of two bytes in hex. Two characters
  1175.  *              for each byte. First two characters in "word" represent
  1176.  *              the byte that was read sooner.
  1177.  *      string == If the character is printable, it is printed.
  1178.  *                Otherwise a '.' is printed. '.'is printed as '.'.
  1179.  *  For each in put file name of the file is first emited.
  1180.  *      file: <i_file>
  1181.  *  last line for each input file is length of the file in 
  1182.  *      "dec_add:hex_add" format.
  1183.  *
  1184.  * Usages:
  1185.  *  hxd [-o] <o_file> <i_files>
  1186.  *
  1187.  *
  1188.  *  Author: Mohsen Banan.
  1189.  *
  1190.  *  This program is public domain software, no warranty intended or
  1191.  *  implied.
  1192.  *  General permission to copy or modify, but not for profit,  is
  1193.  *  hereby  granted.
  1194.  *
  1195.  *
  1196.  * Functions:
  1197.  *
  1198.  *
  1199.  * Audit Trail:  $Log:  hxd.c,v $
  1200.  * Revision 1.1  85/08/28  08:38:36  mohsen
  1201.  * original posting to the net
  1202.  * 
  1203.  * 
  1204.  *
  1205. -*/
  1206.  
  1207. #ifdef RCS_VER
  1208. static char *rcs = "$Header: hxd.c,v 1.1 85/08/28 08:38:36 mohsen Exp $";
  1209. #endif
  1210.  
  1211. /* #includes */
  1212. #include "mbstd.h"
  1213. #include <stdio.h>
  1214. #include <ctype.h>
  1215. #include <fcntl.h>
  1216. #ifdef unix
  1217. #include "msc3.h"
  1218. #endif
  1219.  
  1220. /* #defines */
  1221.  
  1222. /* external variables */
  1223.  
  1224. /* referenced external function declarations */
  1225.  
  1226. /* internal function declarations */
  1227. PUBLIC VOID hxd();
  1228. PUBLIC VOID hxdump();
  1229. PUBLIC VOID cant_open();
  1230. PUBLIC VOID printisc();
  1231. STATIC VOID usage();
  1232.  
  1233. /* global variables */
  1234.  
  1235. /* static variables */
  1236. STATIC CHAR * prog_name;
  1237.  
  1238. INT
  1239. main (argc, argv)
  1240. INT argc;
  1241. CHAR * argv[];
  1242. {
  1243.     hxd(argc, argv);
  1244. }
  1245.     
  1246. ^L
  1247. --MORE--(60%)/*<
  1248.  * Function:hxd
  1249.  * Description:
  1250.  *  Parses the command line and calls hxdump.
  1251.  *  
  1252.  * Returns:
  1253.  *  VOID
  1254.  * 
  1255. >*/
  1256. PUBLIC VOID 
  1257. hxd (argc,argv)
  1258. INT argc;
  1259. CHAR * argv[];
  1260. {
  1261.     FILE * i_fp;
  1262.     FILE * o_fp;
  1263.     INT i;
  1264.  
  1265.     prog_name = argv[0];
  1266.     i_fp = stdin;
  1267.     o_fp = stdout;
  1268.     for (i=1; i<argc; ++i) {
  1269.         if (*argv[i] == '-') {
  1270.             /* To handle concatenated switches */
  1271.             INT j;
  1272.             j=i;
  1273.             while (*(++argv[j])) {
  1274.                 switch (*argv[j]) {
  1275.                 case 'o':
  1276.                 case 'O':
  1277.                     if ( !(o_fp = fopen(argv[++i], "w")) ) {
  1278.                         cant_open(prog_name, argv[i]);
  1279.                         exit(1);
  1280.                     }
  1281.                     break;
  1282.                 default:
  1283.                     usage();
  1284.                     exit(1);
  1285.                 } /* switch (*argv[j]) */
  1286.             } /* while (*(++argv[j])) */
  1287.         } /* if '-' */
  1288.         else {
  1289.             if (!(i_fp = fopen (argv[i], "r"))) {
  1290.                 cant_open (prog_name,  argv[i]);
  1291.                 exit (1);
  1292.             } 
  1293.             fprintf (o_fp, "file:   %s", argv[i]);
  1294.             setmode (fileno(i_fp), O_BINARY);
  1295.             setmode (fileno(o_fp), O_TEXT);
  1296.             hxdump (i_fp, o_fp);
  1297.             fclose (i_fp);
  1298.         }
  1299.     } /* for i<argc */
  1300.     fclose (o_fp);
  1301.     exit (0);
  1302. }
  1303.  
  1304. ^L
  1305. --MORE--(62%)/*<
  1306.  * Function:HX_DUMP
  1307.  * Description:
  1308.  *
  1309.  * Arguments:
  1310.  *
  1311.  * Returns:
  1312.  *
  1313.  * Side Effects:
  1314.  *
  1315.  * Calls:
  1316.  * 
  1317. >*/
  1318. PUBLIC VOID
  1319. hxdump (i_fp, o_fp)
  1320. FILE * i_fp;
  1321. FILE * o_fp;
  1322. {
  1323. #define BYTESPERLINE 16
  1324.     LONG i = 0L;
  1325.     INT c;
  1326.     INT chars[BYTESPERLINE];
  1327.     INT j=0;
  1328.     INT k;
  1329.  
  1330.     while ((c = getc (i_fp)) != EOF) {
  1331.         if (! (i % BYTESPERLINE)) {
  1332.             if (i) {
  1333.                 j=0;
  1334.                 fprintf (o_fp, "  ");
  1335.                 printisc (o_fp,chars, BYTESPERLINE);
  1336.             }
  1337.                 
  1338.             fprintf (o_fp, "\n%07ld:%07lx", i,i );
  1339.         }
  1340.         if (!(i++ & 1)) {
  1341.             putc (' ', o_fp);
  1342.         }
  1343.         fprintf (o_fp, "%02x", c);
  1344.         chars[j++] = c;
  1345.     }
  1346.     if (k = (i % BYTESPERLINE)) {
  1347.         INT jj;
  1348.         k = BYTESPERLINE - k;
  1349.         for (jj=0; jj < (5*k/2)  ;++jj) {
  1350.             putc(' ', o_fp);
  1351.         }
  1352.     }
  1353.     fprintf (o_fp, "  ");
  1354.     printisc (o_fp, chars, BYTESPERLINE);
  1355.     fprintf (o_fp, "\n%07ld:%07lx\n", i,i);
  1356. }
  1357.  
  1358. PUBLIC VOID
  1359. cant_open (prog_name,filename)
  1360. CHAR * prog_name;
  1361. CHAR * filename;
  1362. {
  1363.     fprintf (stderr, "%s :can not open %s \n", prog_name, filename);
  1364.  
  1365. STATIC VOID
  1366. usage ()
  1367. {
  1368.     fprintf (stderr, "Usage: %s [-o] <o_file> <i_file> \n", prog_name);
  1369.      
  1370. }
  1371.  
  1372.  
  1373. PUBLIC VOID
  1374. printisc (o_fp, chars, length)
  1375. FILE * o_fp;
  1376. INT chars[];
  1377. INT length;
  1378. {
  1379.     INT i;
  1380.  
  1381.     for (i=0; i<length; ++i) {
  1382.         if (isprint (chars[i])) {
  1383.             putc (chars[i], o_fp);
  1384.         } else {
  1385.             putc ('.', o_fp);
  1386.         }
  1387.     }
  1388. }
  1389. !Funky!Stuff!
  1390. echo x - sarch.c
  1391. cat >sarch.c <<'!Funky!Stuff!'
  1392. /*+
  1393.  * File: SARCH
  1394.  * Description:
  1395.  *      This is a simple archive utility program.
  1396.  *      Sarch tries to only rely on the C stdio library functions.
  1397.  *      When transferring multiple files between two machines that only have a
  1398.  *      single file transfer utility, sarch becomes handy. Multiple files
  1399.  *      are converted to a sinle file on one end, transfered to the other 
  1400.  *      machine and extracted to the original files at the destination.
  1401.  *      System dependent features are very few, keeping it simple
  1402.  *      and portable. Efficiency is sacrificed for portability.
  1403.  *              CRCs are computed when updateing and when extracting.
  1404.  *  
  1405.  * Usage:
  1406.  *  sarch -{m,u,x,a,t} archname file1 .. filen
  1407.  *      -m      Print file names within the archive.
  1408.  *      -u      Add or update files to the archive.
  1409.  *      -x      Extract files from archive.
  1410.  *      -a      Extract all files from the rachive.
  1411.  *      -t      PCDOS related. When extracting, test mode is set.
  1412.  *
  1413.  *
  1414.  *  Author: Mohsen Banan.
  1415.  *
  1416.  *  This program is public domain software, no warranty intended or
  1417.  *  implied.
  1418.  *  General permission to copy or modify, but not for profit,  is
  1419.  *  hereby  granted.
  1420.  *
  1421.  *
  1422.  * Functions:
  1423.  *
  1424.  *  Sarch relies on the archive manipulating functions:
  1425.  *      ar_open(), ar_close()
  1426.  *      ar_get(), ar_put(), ar_seek().
  1427.  *      ar_get, gets (extracts) a file from the archive.
  1428.  *      ar_put, puts (adds) a file to the archive.
  1429.  *
  1430.  *
  1431.  * Audit Trail:  $Log:  sarch.c,v $
  1432.  * Revision 1.1  85/08/28  08:38:52  mohsen
  1433.  * original posting to the net
  1434.  * 
  1435.  * Revision 1.1  85/08/13  17:30:27  mohsen
  1436.  * Initial revision
  1437.  * 
  1438.  * Revision 1.2  85/04/25  10:27:22  mohsen
  1439.  * In this version sarch was working fine with the -a and -u options.
  1440.  * 
  1441.  * Revision 1.1  85/04/19  16:24:43  mohsen
  1442.  * Initial revision
  1443.  * 
  1444.  *
  1445. -*/
  1446.  
  1447. #ifdef RCS_VER
  1448. static char *rcs = "$Header: sarch.c,v 1.1 85/08/28 08:38:52 mohsen Exp $";
  1449. #endif
  1450.  
  1451. /* #includes */
  1452. #include "mbstd.h"
  1453. #include <stdio.h>
  1454. #include <fcntl.h>
  1455. #ifdef unix
  1456. #include "msc3.h"
  1457. #endif
  1458.  
  1459. /* #defines */
  1460. #define AR_BSTR     "<archive>"
  1461. #define AR_ESTR     "<archive>"
  1462.  
  1463. /*
  1464.  * All fileds of ARCH_HDR are strings (0 terminated),
  1465.  * All fields are left justified.
  1466.  */
  1467. typedef struct {
  1468.     CHAR ar_bstr[16];       /* begining archive string */
  1469.     CHAR fname[16];
  1470.     CHAR fsize[8];
  1471.     CHAR fcrc[8];
  1472.     CHAR ar_estr[16];       /* end archive string */
  1473. } ARCH_HDR;
  1474.  
  1475. /* external variables */
  1476.  
  1477. /* referenced external function declarations */
  1478. EXTERN USHORT fcrc16();
  1479.  
  1480. /* internal function declarations */
  1481. PUBLIC VOID sarch();
  1482. PUBLIC FILE * ar_open();
  1483. PUBLIC INT ar_close();
  1484. PUBLIC SUCC_FAIL ar_put();
  1485. PUBLIC SUCC_FAIL ar_get();
  1486. PUBLIC SUCC_FAIL ar_seek();
  1487. LOCAL VOID wr_hdr();
  1488. LOCAL SUCC_FAIL rd_hdr();
  1489. LOCAL VOID fld2str();
  1490. PUBLIC VOID cpf();
  1491. PUBLIC VOID cant_open();
  1492. STATIC VOID usage();
  1493.  
  1494. /* global variables */
  1495.  
  1496. /* static variables */
  1497. STATIC CHAR * prog_name;
  1498. STATIC ARCH_HDR gw_hdr;         /* generic write archive header */
  1499. STATIC ARCH_HDR gr_hdr;         /* generic read archive header */
  1500. STATIC BOOL txt_mode_flag;
  1501.  
  1502. INT
  1503. main (argc, argv)
  1504. INT argc;
  1505. CHAR * argv[];
  1506. {
  1507.     sarch(argc, argv);
  1508. }
  1509.     
  1510. ^L
  1511. --MORE--(72%)/*<
  1512.  * Function:SARCH
  1513.  * Description:
  1514.  *  Parses the command line and relies on archive manipulating functions to do
  1515.  *  what it should do.
  1516.  *
  1517.  * Returns:
  1518.  *  VOID
  1519.  * 
  1520. >*/
  1521. PUBLIC VOID 
  1522. sarch (argc,argv)
  1523. INT argc;
  1524. CHAR * argv[];
  1525. {
  1526.     FILE * ar_fp;
  1527.  
  1528.     BOOL    add_flag;
  1529.     BOOL    xt_flag;
  1530.     BOOL    xt_all_flag;
  1531.  
  1532.     INT i;
  1533.  
  1534.     add_flag = xt_flag = xt_all_flag = txt_mode_flag = FALSE;
  1535.     ar_fp = stdout;
  1536.     prog_name = argv[0];
  1537.  
  1538.     sprintf (gw_hdr.ar_bstr, "%-15s", AR_BSTR);
  1539.     sprintf (gw_hdr.ar_estr, "%-15s", AR_ESTR);
  1540.  
  1541.     for (i=1; i<argc; ++i) {
  1542.         if (*argv[i] == '-') {
  1543.             /* To handle concatenated switches */
  1544.             INT j;
  1545.             j=i;
  1546.             while (*(++argv[j])) {
  1547.                 switch (*argv[j]) {
  1548.                 case 'u':
  1549.                 case 'U':
  1550.                     /*
  1551.                      * add or update a file to the archive
  1552.                      */
  1553.                     if (!(ar_fp = ar_open (argv[++i], "w"))) {
  1554.                         cant_open(prog_name, argv[i]);
  1555.                         exit (1);
  1556.                     }
  1557.                     add_flag = TRUE;
  1558.                     break;
  1559.                 case 'x':
  1560.                 case 'X':
  1561.                     /*
  1562.                      * Extract a file from the archive.
  1563.                      */
  1564.                     if (!(ar_fp = ar_open (argv[++i], "r"))) {
  1565.                         cant_open(prog_name,argv[i]);
  1566.                         exit(1);
  1567.                     }
  1568.                     xt_flag = TRUE;
  1569.                     break;
  1570.                 case 'a':
  1571.                 case 'A':
  1572.                     /*
  1573.                      * Extract all files with in this archive
  1574.                      */
  1575.                     if (!(ar_fp = ar_open (argv[i+1], "r"))) {
  1576.                         cant_open(prog_name,argv[i]);
  1577.                         exit(1);
  1578.                     }
  1579.                     xt_all_flag = TRUE;
  1580.                     break;
  1581.                 case 't':
  1582.                 case 'T':
  1583.                     txt_mode_flag = TRUE;
  1584.                     break;
  1585.                 default:
  1586.                     usage();
  1587.                     exit(1);
  1588.                 } /* switch (*argv[j]) */
  1589.             } /* while (*(++argv[j])) */
  1590.         } /* if '-' */
  1591.         else if (ar_fp == stdout) {
  1592.             /* 
  1593.              * This is equivalent to "-u" option, ar_fp is stdout.
  1594.              */
  1595.              add_flag = TRUE;
  1596.         }
  1597.         else {
  1598.             /*
  1599.              * the rest of command line arguments are assumed to be file names.
  1600.              */
  1601.             if (add_flag) {
  1602.                 ar_put (ar_fp, &gw_hdr,argv[i]);
  1603.             }
  1604.             else if (xt_flag) {
  1605.                 ar_seek (ar_fp, &gr_hdr, argv[i]);
  1606.                 ar_get (ar_fp,&gr_hdr);
  1607.             }
  1608.             else if (xt_all_flag) {
  1609.                 while ( ar_seek (ar_fp, &gr_hdr,(CHAR *) NULL) == SUCCESS ) {
  1610.                     ar_get (ar_fp, &gr_hdr);
  1611.                 }
  1612.             }
  1613.             else {
  1614.                 /*
  1615.                 OOPS();
  1616.                 */
  1617.             }
  1618.         }
  1619.     } /* for i<argc */
  1620.     ar_close (ar_fp);
  1621.     exit (0);
  1622. }
  1623.  
  1624. ^L
  1625. --MORE--(79%)/*<
  1626.  * Function:ar_open
  1627.  * Description:
  1628.  *  Opens an archive directory.
  1629.  *
  1630.  * Returns:
  1631.  *  Same as fopen.
  1632.  *
  1633.  * 
  1634. >*/
  1635. PUBLIC FILE *
  1636. ar_open(path, type)
  1637. CHAR * path;
  1638. CHAR * type;
  1639. {
  1640.     FILE * fp;
  1641.     if ( fp=fopen(path,type) ) {
  1642.         setmode (fileno(fp), O_BINARY);
  1643.     }
  1644.     return (fp);
  1645. }
  1646.  
  1647.  
  1648.  
  1649. /*<
  1650.  * Function:ar_close
  1651.  * Description:
  1652.  *  Closes an archive file
  1653.  *
  1654.  * Returns:
  1655.  *  same as fclose.
  1656.  * 
  1657. >*/
  1658. PUBLIC INT
  1659. ar_close(ar_fp)
  1660. FILE * ar_fp;
  1661. {
  1662.     return (fclose(ar_fp));
  1663. }
  1664.  
  1665.  
  1666. ^L
  1667. --MORE--(80%)/*<
  1668.  * Function: ar_put
  1669.  * Description:
  1670.  *  Puts the contents of the file specified in "path" into the archive.
  1671.  *  Archive header is written prior to copying the file.
  1672.  *
  1673.  * Returns:
  1674.  *  SUCCESS:    
  1675.  *      No problems.
  1676.  *  FAIL:
  1677.  *      Couldn't open the file that it is supposed to put it in.
  1678.  * 
  1679. >*/
  1680. PUBLIC SUCC_FAIL
  1681. ar_put(ar_fp, p_ar_hdr, path)
  1682. FILE * ar_fp;
  1683. ARCH_HDR * p_ar_hdr;
  1684. CHAR * path;
  1685. {
  1686.     FILE * fp;
  1687.     SUCC_FAIL retval;
  1688.     LONG fsize;
  1689.     USHORT crc;
  1690.  
  1691.     retval = SUCCESS;
  1692.     if (!(fp = fopen(path, "r"))) {
  1693.         cant_open (prog_name, path);
  1694.         retval = FAIL;
  1695.     } else {
  1696.         setmode (fileno(fp), O_BINARY);
  1697.         crc = fcrc16(fp, (USHORT)0, &fsize);
  1698.         rewind(fp);
  1699.         sprintf (p_ar_hdr->fsize, "%-7ld", fsize);
  1700.         sprintf (p_ar_hdr->fcrc, "%-7x", (int)crc);
  1701.         sprintf (p_ar_hdr->fname, "%-15s", path);
  1702.         wr_hdr(ar_fp, p_ar_hdr);
  1703.         cpf (fp, ar_fp, fsize);
  1704.         fclose(fp);
  1705.     }
  1706.     return (retval);
  1707. }
  1708.  
  1709. ^L
  1710. --MORE--(82%)/*<
  1711.  * Function:ar_get
  1712.  * Description:
  1713.  *  Gets (extracts) the contents of a file from the archive.
  1714.  *  and stores it in the file specified in the archive header.
  1715.  *  ar_get is to be invoked after the execution of ar_seek.
  1716.  *
  1717.  * Returns:
  1718.  *  SUCCESS:
  1719.  *      Every thing went fine.
  1720.  *  FAIL:
  1721.  *      Couldn't open the file.
  1722.  *
  1723.  * 
  1724. >*/
  1725. PUBLIC SUCC_FAIL
  1726. ar_get(ar_fp, p_ar_hdr)
  1727. FILE  * ar_fp;
  1728. ARCH_HDR * p_ar_hdr;
  1729. {
  1730.     FILE * fp;
  1731.     SUCC_FAIL retval;
  1732.     LONG fsize;
  1733.     LONG nfsize;
  1734.     USHORT crc;
  1735.     USHORT ncrc;
  1736.     UINT   int_crc;
  1737.  
  1738.     retval = SUCCESS;
  1739.  
  1740.     if (!(fp = fopen(p_ar_hdr->fname, "w+"))) {
  1741.         cant_open (prog_name, p_ar_hdr->fname);
  1742.         retval = FAIL;
  1743.     } else {
  1744.                 setmode(fileno(fp), O_BINARY);
  1745.         sscanf (p_ar_hdr->fsize, "%ld", &fsize);
  1746.         cpf((FILE *)ar_fp, fp, fsize);
  1747.         rewind(fp);
  1748.         ncrc = fcrc16(fp, (USHORT)0, &nfsize);
  1749.         sscanf (p_ar_hdr->fcrc, "%x", &int_crc);
  1750.         crc = int_crc;
  1751.         if ( (crc != ncrc) || (fsize != nfsize) ) {
  1752.             retval = FAIL;
  1753.             fprintf(stderr, "%s: Problem extacting %s size=%ld, crc=%x\n",
  1754.                     prog_name, p_ar_hdr->fname, fsize, (int)crc);
  1755.             fprintf(stderr, "%s: Problem extacting %s nsize=%ld, ncrc=%x\n",
  1756.                     prog_name, p_ar_hdr->fname, nfsize, (int)ncrc);
  1757.         }
  1758.         fclose(fp);
  1759.     }
  1760.     return (retval);
  1761. }
  1762.  
  1763. ^L
  1764. --MORE--(85%)/*<
  1765.  * Function: ar_seek
  1766.  * Description:
  1767.  *  If path is NULL, the current archive header is read into
  1768.  *  p_ar_hdr.
  1769.  *  Otherwise, the archive is searched for the specified file
  1770.  *  name addressed by path.
  1771.  *
  1772.  * Returns:
  1773.  *  SUCCESS if found.
  1774.  *  FAIL    if not found, or problem.
  1775.  *
  1776.  * 
  1777. >*/
  1778. LOCAL SUCC_FAIL
  1779. ar_seek(ar_fp, p_ar_hdr, path) 
  1780. FILE * ar_fp;
  1781. ARCH_HDR * p_ar_hdr;
  1782. CHAR * path;
  1783. {
  1784.     SUCC_FAIL retval;
  1785.  
  1786.     retval = SUCCESS;
  1787.     if (!path ) {
  1788.         /* then get it any way */
  1789.         retval = rd_hdr(ar_fp, p_ar_hdr);
  1790.     } else {
  1791.         
  1792.     }
  1793.     return (retval);
  1794. }
  1795.  
  1796. ^L
  1797. --MORE--(86%)/*<
  1798.  * Function:wr_hdr
  1799.  * Description:
  1800.  *  Copy the contents of ARCH_HDR to the archive header.
  1801.  *  See rd_hdr for the file archive header picture.
  1802.  *
  1803.  * Returns:
  1804.  *  VOID
  1805.  * 
  1806. >*/
  1807. LOCAL VOID
  1808. wr_hdr (ar_fp, p_ar_hdr)
  1809. FILE * ar_fp;
  1810. ARCH_HDR * p_ar_hdr;
  1811. {
  1812.     fprintf (ar_fp , "%-15s", p_ar_hdr->ar_bstr);
  1813.     fprintf (ar_fp , "%-15s", p_ar_hdr->fname);
  1814.     fprintf (ar_fp , "%-7s", p_ar_hdr->fsize);
  1815.     fprintf (ar_fp , "%-7s", p_ar_hdr->fcrc);
  1816.     fprintf (ar_fp , "%-15s", p_ar_hdr->ar_estr);
  1817.     putc ('\n',ar_fp);
  1818. }
  1819.  
  1820. ^L
  1821. --MORE--(87%)/*<
  1822.  * Function:rd_hdr
  1823.  * Description:
  1824.  *  Reads a header and fills up the ARCH_HDR.
  1825.  *
  1826. 0         1         2         3         4         5         6   
  1827. 0123456789012345678901234567890123456789012345678901234567890
  1828. 123456789012345678901234567890123456789012345678901234567890
  1829. b              b              b      b     b
  1830.     ar_bstr        fname        fsize  fcrc     ar_estr
  1831.  *
  1832.  * Returns:
  1833.  *  SUCCESS:
  1834.  *  FAIL:
  1835.  *      archive header is bad.
  1836.  *
  1837.  * 
  1838. >*/
  1839. LOCAL SUCC_FAIL
  1840. rd_hdr (ar_fp, p_ar_hdr)
  1841. FILE * ar_fp;
  1842. ARCH_HDR * p_ar_hdr;
  1843. {
  1844.     SUCC_FAIL   retval;
  1845.     CHAR    hdr_line[256];
  1846.     INT i;
  1847.  
  1848.     retval = SUCCESS;
  1849.     if (!fgets (hdr_line, 255,ar_fp)) {
  1850.         retval = FAIL;
  1851.     } else {
  1852.         fld2str (&hdr_line[0], p_ar_hdr->ar_bstr, 15);
  1853.  
  1854.         for (i=15; i<30; ++i) {
  1855.             if ( hdr_line[i] != ' ') {  
  1856.                 p_ar_hdr->fname[i-15] = hdr_line[i];
  1857.             } else {
  1858.                 break;
  1859.             }
  1860.         }
  1861.         p_ar_hdr->fname[i-15] = '\0';
  1862.                 
  1863.         fld2str (&hdr_line[30], p_ar_hdr->fsize, 7);
  1864.         fld2str (&hdr_line[37], p_ar_hdr->fcrc, 7);
  1865.         fld2str (&hdr_line[43], p_ar_hdr->ar_estr, 15);
  1866.     }
  1867.     return (retval);
  1868.  
  1869. }
  1870.  
  1871. LOCAL VOID
  1872. fld2str ( fld, str, size)
  1873. CHAR * fld;
  1874. CHAR * str;
  1875. INT size;
  1876. {
  1877.     INT i;
  1878.     for (i=0; i<size; ++i) {
  1879.         *str++ = *fld++;
  1880.     }
  1881.     *str = '\0';
  1882. }
  1883.  
  1884.     
  1885. ^L
  1886. --MORE--(90%)/*<
  1887.  * Function:cpf
  1888.  * Description:
  1889.  *  Copy the first <fsize> bytes of <src_fp> to <dst_fp>
  1890.  *
  1891.  * Returns:
  1892.  *      VOID
  1893.  *
  1894.  * Side Effects:
  1895.  *      Both src_fp and dst_fp characters pointers are moved.
  1896.  *
  1897. >*/
  1898. LOCAL VOID
  1899. cpf (src_fp, dst_fp, fsize)
  1900. FILE * src_fp;
  1901. FILE * dst_fp;
  1902. LONG fsize;
  1903. {
  1904.     LONG i;
  1905.     for (i=0; i<fsize; ++i) {
  1906.         putc(getc(src_fp), dst_fp);
  1907.     }
  1908. }
  1909.  
  1910.  
  1911. PUBLIC VOID
  1912. cant_open (prog_name,filename)
  1913. CHAR * prog_name;
  1914. CHAR * filename;
  1915. {
  1916.     fprintf (stderr, "%s :can not open %s \n", prog_name, filename);
  1917.  
  1918. STATIC VOID
  1919. usage ()
  1920. {
  1921.     fprintf (stderr, "Usage: %s [-u] [-x] <filename> \n", prog_name);
  1922. }
  1923.  
  1924. !Funky!Stuff!
  1925. echo x - which.c
  1926. cat >which.c <<'!Funky!Stuff!'
  1927. /*+
  1928.  * File: which.c
  1929.  * Description:
  1930.  *  Tries to mimic Unix's which as closely as possible.
  1931.  *  
  1932.  * Usages:
  1933.  *  which <i_files>
  1934.  * 
  1935.  *
  1936.  *  Author: Mohsen Banan.
  1937.  *
  1938.  *  This program is public domain software, no warranty intended or
  1939.  *  implied.
  1940.  *  General permission to copy or modify, but not for profit,  is
  1941.  *  hereby  granted.
  1942.  *
  1943.  * Functions:
  1944.  *
  1945.  *
  1946.  * Audit Trail:  $Log:  which.c,v $
  1947.  * Revision 1.1  85/08/28  08:38:54  mohsen
  1948.  * original posting to the net
  1949.  * 
  1950.  * 
  1951.  *
  1952. -*/
  1953.  
  1954. #ifdef RCS_VER
  1955. static char *rcs = "$Header: which.c,v 1.1 85/08/28 08:38:54 mohsen Exp $";
  1956. #endif
  1957.  
  1958. /* #includes */
  1959. #include "mbstd.h"
  1960. #include <stdio.h>
  1961.  
  1962. /* #defines */
  1963. #ifdef BSD4_2
  1964. #define strchr index
  1965. #endif
  1966.  
  1967. /* external variables */
  1968.  
  1969. /* referenced external function declarations */
  1970. EXTERN char *getenv();
  1971. EXTERN char *strchr();
  1972. EXTERN char *strcat();
  1973.  
  1974. /* internal function declarations */
  1975. PUBLIC VOID which();
  1976. STATIC CHAR * get_head();
  1977. STATIC BOOL is_runable();
  1978. STATIC VOID usage();
  1979.  
  1980. /* global variables */
  1981.  
  1982. /* static variables */
  1983. STATIC CHAR * prog_name;
  1984.  
  1985. INT
  1986. main (argc, argv)
  1987. INT argc;
  1988. CHAR * argv[];
  1989. {
  1990.     which(argc, argv);
  1991. }
  1992.     
  1993. ^L
  1994. --MORE--(94%)/*<
  1995.  * Function:which
  1996.  * Description:
  1997.  *
  1998.  * Returns:
  1999.  *  VOID
  2000.  * 
  2001. >*/
  2002. PUBLIC VOID 
  2003. which (argc,argv)
  2004. INT argc;
  2005. CHAR * argv[];
  2006. {
  2007.  
  2008.     INT i;
  2009.     CHAR * head, * nxt_head;        /* head concept is a-la Csh */
  2010.     BOOL end_of_path;
  2011.     BOOL not_in_path;
  2012.     STATIC CHAR file_buf[256];
  2013.     STATIC CHAR path_buf[512];
  2014.     CHAR * orig_path;
  2015.  
  2016.     prog_name = argv[0];
  2017.     if (argc < 2) {
  2018.         usage();
  2019.         exit(1);
  2020.     }
  2021.     if ((orig_path = getenv("PATH")) == NULL) {
  2022.         orig_path = ".";
  2023.     }
  2024.     for (i=1; i<argc; ++i) {
  2025.         end_of_path = FALSE;
  2026.         not_in_path = TRUE;
  2027.         strcpy (path_buf, orig_path);
  2028.         nxt_head = head = path_buf;
  2029.         while ( ! end_of_path ) {
  2030.             nxt_head = get_head (head);
  2031.             if ( nxt_head == NULL) {
  2032.                 end_of_path = TRUE;
  2033.             } else {
  2034.                 *nxt_head = '\0';
  2035.             }
  2036. #ifdef unix
  2037.             sprintf (file_buf, "%s/%s",(*head ? head:"."), argv[i]);
  2038. #endif
  2039. #ifdef MSDOS
  2040.             sprintf (file_buf, "%s\\%s",(*head ? head:"."), argv[i]);
  2041. #endif
  2042.             head = ++nxt_head;
  2043.             if ( is_runable(file_buf) ) {
  2044.                 printf ("%s\n", file_buf);
  2045.                 not_in_path = FALSE;
  2046.             }
  2047.         }
  2048.         if ( not_in_path ) {
  2049.             printf ("No %s in %s\n", argv[i], orig_path);
  2050.         }
  2051.     } /* for i<argc */
  2052.     exit (0);
  2053. }
  2054.  
  2055. STATIC VOID
  2056. usage ()
  2057. {
  2058.     fprintf (stderr, "Usage: %s cmd [cmd, ..]\n", prog_name);
  2059. }
  2060.  
  2061.  
  2062. STATIC CHAR * 
  2063. get_head (head)
  2064. CHAR * head;
  2065. {
  2066. #ifdef unix
  2067.     return (strchr( head, ':'));
  2068. #endif
  2069. #ifdef MSDOS
  2070.     return (strchr( head, ';'));
  2071. #endif
  2072. }
  2073.  
  2074. STATIC BOOL
  2075. is_runable (file_buf)
  2076. CHAR * file_buf;
  2077. {
  2078.     BOOL ret_val;
  2079.     CHAR * name, * root_name;   /* root is as defined by Csh */
  2080.  
  2081.     ret_val = FALSE;
  2082. #ifdef unix
  2083.     if ( access(file_buf, 1) == 0 ) {
  2084.         ret_val = TRUE;
  2085.     }
  2086. #endif
  2087. #ifdef MSDOS
  2088.     for (root_name=file_buf; *root_name; ++root_name);
  2089.     name = strcat(file_buf, ".com");
  2090.     if ( access(name, 0) == 0 ) {
  2091.         ret_val = TRUE;
  2092.     }
  2093.     else {
  2094.         *root_name = '\0';
  2095.         name = strcat(file_buf, ".exe");
  2096.         if ( access(name, 0) == 0 ) {
  2097.             ret_val = TRUE;
  2098.         }
  2099.         else {
  2100.             *root_name = '\0';
  2101.             name = strcat(file_buf, ".bat");
  2102.             if ( access(name, 0) == 0 ) {
  2103.                 ret_val = TRUE;
  2104.             }
  2105.         }
  2106.     }
  2107.     printf ("\n %s \n", name);
  2108. #endif
  2109.     return (ret_val);
  2110. }
  2111. !Funky!Stuff!
  2112.  
  2113.  
  2114. -- 
  2115.  
  2116.        !uw-beaver!tikal!mohsen                Mohsen Banan
  2117.        Teltone Corporation                    11811 93rd Ave. N.E. #304
  2118.        P.O. Box 657                           Kirkland, Wa 98033  USA
  2119.        Kirkland, Wa 98033  USA                tel: +1 (206) 821-8560
  2120.        tel: +1 (206) 827-9626               
  2121. (Mail) End of article 2703 (of 2730)--what next? [npq]